﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace CarBlackBox
{
    public partial class Form_ProductEditor : Form
    {
        bool bClose = true;
        Form_ProductManage F;
        public Form_ProductEditor(Form_ProductManage f)
        {
            InitializeComponent();
            F = f;
        }

        private void Form_ProductEditor_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {            
            int n = 0;
            try
            {
                n = recordInfoTableAdapter.Insert(textBox1.Text);
            }
            catch (OleDbException ex)
            {
                if (ex.ErrorCode == -2147467259)//主键已经存在
                {
                    MessageBox.Show("添加失败，当前记录仪序列号已经存在!!!");
                    textBox1.Focus();
                    textBox1.SelectAll();
                    return;
                }
            }                
            if (n != 1)
                MessageBox.Show("存储失败，请重新尝试或联系管理员!!!!");
            else
            {
                F.RenovateRecordInfo();
                WFNetLib.Log.SystemLogData log = new WFNetLib.Log.SystemLogData();
                log.LogType = LogType.记录仪管理.ToString();
                log.LogContent = "添加:" + textBox1.Text;
                log.LogRemark = "记录仪添加";
                log.InserSQLLog();
                if (WFNetLib.WFGlobal.MessageYseOrNo("存储成功\r\nYes继续添加\r\nNo退出添加", "成功") == DialogResult.Yes)
                {
                    textBox1.Focus();
                    textBox1.SelectAll();
                }
                else
                {
                    this.DialogResult = DialogResult.OK;
                }
            }
        }

        private void Form_ProductEditor_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!bClose)
            {
                e.Cancel = true;
                bClose = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (WFNetLib.WFGlobal.MessageYseOrNo("确定取消当前操作么？", "产品信息编辑取消") == DialogResult.No)
                bClose = false;
        }
    }
}
